// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   register_batch_ok.java

package oa.messager;

import com.jspsmart.upload.*;
import include.nseer_cookie.counter;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class register_batch_ok extends HttpServlet
{

	public register_batch_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			response.setContentType("text/html;charset=UTF-8");
			HttpSession session = request.getSession();
			counter count = new counter(dbApplication);
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			nseer_db_backup1 oa_db = new nseer_db_backup1(dbApplication);
			if (oa_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				mySmartUpload.initialize(pageContext);
				mySmartUpload.upload();
				String file_name = "";
				int n = 0;
				SmartFile file = mySmartUpload.getFiles().getFile(0);
				if (!file.isMissing())
				{
					if (file.getFileName().indexOf(".txt") == file.getFileName().length() - 4)
					{
						int filenum = count.read((String)dbSession.getAttribute("unit_db_name"), "oaAttachmentcount");
						count.write((String)dbSession.getAttribute("unit_db_name"), "oaAttachmentcount", filenum);
						file_name = (new StringBuilder(String.valueOf(path))).append("oa/file_attachments/").append(filenum).append(file.getFileName()).toString();
						file.saveAs((new StringBuilder(String.valueOf(path))).append("oa/file_attachments/").append(filenum).append(file.getFileName()).toString());
						String messager_type = mySmartUpload.getRequest().getParameter("messager_type");
						String tool_type = mySmartUpload.getRequest().getParameter("tool_type");
						String register_ID = (String)session.getAttribute("human_IDD");
						String register = (String)session.getAttribute("realeditorc");
						Date now = new Date();
						SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						String time = formatter.format(now);
						RandomAccessFile filee = new RandomAccessFile(file_name, "r");
						long filePointer = 0L;
						for (long length = filee.length(); filePointer < length; filePointer = filee.getFilePointer())
						{
							String mk = filee.readLine();
							byte bbbbb[] = mk.getBytes("8859_1");
							String content = new String(bbbbb, "UTF-8");
							String sql = (new StringBuilder("select * from oa_messager where content='")).append(content).append("' and type='").append(tool_type).append("'").toString();
							ResultSet rs = oa_db.executeQuery(sql);
							if (!rs.next())
							{
								String sql1 = (new StringBuilder("insert into oa_messager(register,register_ID,register_time,type,tool_type,content) values('")).append(register).append("','").append(register_ID).append("','").append(time).append("','").append(messager_type).append("','").append(tool_type).append("','").append(content).append("')").toString();
								oa_db.executeUpdate(sql1);
							}
						}

						response.sendRedirect("oa/messager/register_batch_ok_b.jsp");
					} else
					{
						response.sendRedirect("oa/messager/register_batch_ok_a.jsp");
					}
				} else
				{
					response.sendRedirect("oa/messager/register_batch_ok_c.jsp");
				}
				oa_db.commit();
				oa_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
